// "Copyright 2018 <Fabio M. Graetz>"
#include <stdlib.h>
#include <iostream>
#include "./utils.h"

#include "./gputimer.h"

#define BLOCK_NUM 32 // 块数量
#define THREAD_NUM 256



int main(int argc, char **argv) {
  // 分配空间
  int *mat1, *mat2, *result;
  int *

  GpuTimer timer;
  timer.Start();
  gaussian_blur(h_inputImageRGBA, d_inputImageRGBA, d_outputImageRGBA,
                numRows(), numCols(), d_redBlurred, d_greenBlurred,
                d_blueBlurred, filterWidth);
  timer.Stop();
  cudaDeviceSynchronize();
  checkCudaErrors(cudaGetLastError());

  cout << "Your code ran in: " << timer.Elapsed() << "msecs." << endl;
  
  // copies result back to host
  size_t numPixels = numRows() * numCols();
  checkCudaErrors(cudaMemcpy(h_outputImageRGBA, d_outputImageRGBA,
                             sizeof(uchar4) * numPixels,
                             cudaMemcpyDeviceToHost));
  // outputs blurred image
  postProcess(output_file, h_outputImageRGBA);
  // creates and outputs a reference blurredimage on CPU
  referenceCalculation(h_inputImageRGBA, h_outputImageRGBA, numRows(), numCols(),
  h_filter, filterWidth);
  postProcess("ref.png", h_outputImageRGBA);

  // frees memory on GPU
  checkCudaErrors(cudaFree(d_redBlurred));
  checkCudaErrors(cudaFree(d_greenBlurred));
  checkCudaErrors(cudaFree(d_blueBlurred));
  cleanup();
  cleanupCu();
}
